<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_3752867_0vt14114p53.css">
    <style>
        body {
            position: relative;
        }

        span {
            position: absolute;
            left: 150px;
            top: 4px;
        }
    </style>
</head>

<body>
    <input type="password" name="" id="">
    <span class="iconfont icon-closed"></span>
    <script>
        // 获取到密码框和span标签
        let input = document.querySelector("input")
        let span = document.querySelector("span")
        // 给span添加点击事件
        span.addEventListener("click", function () {
            if (input.type == "password") {
                span.classList.remove("icon-closed")
                span.classList.add("icon-open")
                input.type = "text"

            } else {

                span.classList.remove("icon-open")
                span.classList.add("icon-closed")
                input.type = "password"
            }

        })
    </script>
</body>

</html>